// 导入request请求工具类
import {
    getBaseUrl,
    requestUtil
} from '../../utils/requestUtil.js';
import regeneratorRuntime from '../../lib/runtime/runtime';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseUrl: '',
        shoucang: []
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        const baseUrl = getBaseUrl();
        this.setData({
            baseUrl
        })
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        console.log("show")
        const shoucang = wx.getStorageSync('shoucang') || [];
        this.setData({
            shoucang
        })
    },
    // 商品数量的编辑功能
    handleItemNumEdit(e) {
        const {
            operation,
            id
        } = e.currentTarget.dataset;
        console.log(operation, id);
        let {
            shoucang
        } = this.data;
        let index = shoucang.findIndex(v => v.id === id);
        wx.showModal({
            title: '系统提示',
            content: '您是否要取消关注？',
            cancelColor: 'cancelColor',
            success: (res) => {
                if (res.confirm) {
                    shoucang.splice(index, 1);
                    wx.setStorageSync('shoucang', shoucang);
                    wx.switchTab({
                        url: '/pages/my/index'
                      })
                }
            },
        })
    },
})